#include <cstdio>

double f[ 1002 ][ 1002 ], a[ 1002 ][ 1002 ], b[ 1002 ][ 1002 ], c[ 1002 ][ 1002 ];
int n, m;

void init( )
{
    int i, j;
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < m; j++ )
            scanf("%lf%lf%lf", &a[ i ][ j ], &b[ i ][ j ], &c[ i ][ j ]);
    f[ n - 1 ][ m - 1 ] = 0;
}

void work( )
{
    int i, j;
    for ( i = n - 1; i >= 0; i-- )
        for ( j = m - 1; j >= 0; j-- )
        {
            if ( i == n - 1 && j == m - 1 ) continue;
            if ( 1 - a[ i ][ j ] < 1e-8 )
                f[ i ][ j ] = 0;
            else
                f[ i ][ j ] = ( 2 * a[ i ][ j ] + b[ i ][ j ] * ( f[ i ][ j + 1 ] + 2 ) + c[ i ][ j ] * ( f[ i + 1 ][ j ] + 2 ) ) / ( 1 - a[ i ][ j ] );
        }
    printf("%.3lf\n", f[ 0 ][ 0 ]);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
